package leetcode.offer;

import java.util.LinkedList;
import java.util.List;

/**
 * ClassName: Offer57II_FindContinuousSequence
 * Description:
 * date: 2021-11-19 23:16
 *
 * @author liyifan
 */
public class Offer57II_FindContinuousSequence {
    public int[][] findContinuousSequence(int target) {
        int left = 1;
        int right = 2;
        int sum = 3;
        List<int[]> res = new LinkedList<>();
        while (left < right) {
            if (sum == target) {
                int[] ans = new int[right - left + 1];
                for (int i = left;i <= right;i++) {
                    ans[i - left] = i;
                }
                res.add(ans);
                left++;
                continue;
            }
            if (sum < target) {
                right++;
                sum += right;
            } else {
                sum -= left;
                left++;
            }
        }
        return res.toArray(new int[0][]);
    }
}
